package com.southpark.system.view
{
	import com.southpark.system.interfaces.managers.IToolTipManager;
	import com.southpark.system.interfaces.view.IToolTipUI;
	import com.southpark.system.view.toolTips.ToolTipTarget;
	
	import flash.events.MouseEvent;
	
	import mx.containers.Box;
	import mx.core.Application;
	
	
	public class AbstractToolTipUI extends Box implements IToolTipUI
	{
		
		public function AbstractToolTipUI()
		{
			addEventListener(MouseEvent.ROLL_OUT,onRollOut);
		}
		
		private var _toolTipManager:IToolTipManager;
		public function set toolTipManager(value:IToolTipManager):void
		{
			_toolTipManager = value;
		}
		
		private var _toolTipTarget:ToolTipTarget;
		public function set toolTipTarget(value:ToolTipTarget):void
		{
			_toolTipTarget = value;
		}
		public function get toolTipTarget():ToolTipTarget
		{
			return _toolTipTarget;
		}
		
		
		public function isMouseTrapped():Boolean
		{
			return hitTestPoint(Application.application.mouseX,Application.application.mouseY,true)
		}
		
		
		private function onRollOut(event:MouseEvent):void
		{
			if (!_toolTipTarget.isMouseTrapped())
			{
				hideToolTip();
			};
		}
		
		public function hideToolTip():void
		{
			_toolTipManager.hideToolTip();
		}
		
	}
}